import 'dart:convert';
import 'package:ichinesereader/models/book/Series.dart';
import 'package:ichinesereader/models/book/BookFeatures.dart';
import 'package:ichinesereader/models/book/InterestLevel.dart';
import 'package:ichinesereader/models/book/BookLevel.dart';
import 'package:ichinesereader/models/book/ProgramTypes.dart';
import 'package:ichinesereader/models/book/TextType.dart';
import 'package:ichinesereader/models/book/TextTypeResp.dart';

List<NewBook> newBookFromJson(String str) =>
    List<NewBook>.from(json.decode(str).map((x) => NewBook.fromJson(x)));

String newBookToJson(List<NewBook> data) =>
    json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class NewBook {
  NewBook({
    this.assessment,
    this.assessmentLevel,
    this.audio,
    this.bilingual,
    this.bookCode,
    this.bookContentLink,
    this.bookFeatures,
    this.bookId,
    this.bookImageLink,
    this.bookTitle,
    this.createTime,
    this.description,
    this.enabled,
    this.endDate,
    this.englishBookTitle,
    this.interestLevels,
    this.keyword,
    this.keywords,
    this.language,
    this.level,
    this.newArival,
    this.proficiencyLevel,
    this.programTypes,
    this.quiz,
    this.quizLinkUrl,
    this.series,
    this.startDate,
    this.teacherAssessment,
    this.teacherResource,
    this.textType,
    this.textTypeResps,
    this.topBook,
    this.topics,
    this.traditionalTitle,
    this.uploadDate,
    this.viewMode,
  });

  bool? assessment;
  String? assessmentLevel;
  String? audio;
  bool? bilingual;
  String? bookCode;
  String? bookContentLink;
  BookFeatures? bookFeatures;
  String? bookId;
  String? bookImageLink;
  String? bookTitle;
  int? createTime;
  String? description;
  bool? enabled;
  int? endDate;
  String? englishBookTitle;
  List<InterestLevel>? interestLevels;
  List<String>? keyword;
  String? keywords;
  String? language;
  Level? level;
  bool? newArival;
  int? proficiencyLevel;
  List<ProgramType>? programTypes;
  bool? quiz;
  String? quizLinkUrl;
  List<Series>? series;
  int? startDate;
  bool? teacherAssessment;
  bool? teacherResource;
  List<TextType>? textType;
  List<TextTypeResp>? textTypeResps;
  bool? topBook;
  List<String>? topics;
  String? traditionalTitle;
  int? uploadDate;
  String? viewMode;

  factory NewBook.fromJson(Map<String, dynamic> json) => NewBook(
        assessment: json["assessment"],
        assessmentLevel: json["assessmentLevel"],
        audio: json["audio"],
        bilingual: json["bilingual"],
        bookCode: json["bookCode"],
        bookContentLink: json["bookContentLink"],
        bookFeatures: json["bookFeatures"] != null
            ? BookFeatures.fromJson(json["bookFeatures"])
            : null,
        bookId: json["bookId"],
        bookImageLink: json["bookImageLink"],
        bookTitle: json["bookTitle"],
        createTime: json["createTime"],
        description: json["description"],
        enabled: json["enabled"],
        endDate: json["endDate"],
        englishBookTitle: json["englishBookTitle"],
        interestLevels: json["interestLevels"] != null
            ? List<InterestLevel>.from(
                json["interestLevels"].map((x) => InterestLevel.fromJson(x)))
            : null,
        keyword: json["keyword"] != null
            ? List<String>.from(json["keyword"].map((x) => x))
            : null,
        keywords: json["keywords"],
        language: json["language"],
        level: json["level"] != null ? Level.fromJson(json["level"]) : null,
        newArival: json["newArival"],
        proficiencyLevel: json["proficiencyLevel"],
        programTypes: json["programTypes"] != null
            ? List<ProgramType>.from(
                json["programTypes"].map((x) => ProgramType.fromJson(x)))
            : null,
        quiz: json["quiz"],
        quizLinkUrl: json["quizLinkUrl"],
        series: json["series"] != null
            ? List<Series>.from(json["series"].map((x) => Series.fromJson(x)))
            : null,
        startDate: json["startDate"],
        teacherAssessment: json["teacherAssessment"],
        teacherResource: json["teacherResource"],
        textType: json["textType"] != null
            ? List<TextType>.from(
                json["textType"].map((x) => TextType.fromJson(x)))
            : null,
        textTypeResps: json["textTypeResps"] != null
            ? List<TextTypeResp>.from(
                json["textTypeResps"].map((x) => TextTypeResp.fromJson(x)))
            : null,
        topBook: json["topBook"],
        topics: json["topics"] != null
            ? List<String>.from(json["topics"].map((x) => x))
            : null,
        traditionalTitle: json["traditionalTitle"],
        uploadDate: json["uploadDate"],
        viewMode: json["viewMode"],
      );

  Map<String, dynamic> toJson() => {
        "assessment": assessment,
        "assessmentLevel": assessmentLevel,
        "audio": audio,
        "bilingual": bilingual,
        "bookCode": bookCode,
        "bookContentLink": bookContentLink,
        "bookFeatures": bookFeatures?.toJson(),
        "bookId": bookId,
        "bookImageLink": bookImageLink,
        "bookTitle": bookTitle,
        "createTime": createTime,
        "description": description,
        "enabled": enabled,
        "endDate": endDate,
        "englishBookTitle": englishBookTitle,
        "interestLevels": interestLevels != null
            ? List<dynamic>.from(interestLevels!.map((x) => x.toJson()))
            : null,
        "keyword":
            keyword != null ? List<dynamic>.from(keyword!.map((x) => x)) : null,
        "keywords": keywords,
        "language": language,
        "level": level != null ? level?.toJson() : null,
        "newArival": newArival,
        "proficiencyLevel": proficiencyLevel,
        "programTypes": programTypes != null
            ? List<dynamic>.from(programTypes!.map((x) => x.toJson()))
            : null,
        "quiz": quiz,
        "quizLinkUrl": quizLinkUrl,
        "series": series != null
            ? List<dynamic>.from(series!.map((x) => x.toJson()))
            : null,
        "startDate": startDate,
        "teacherAssessment": teacherAssessment,
        "teacherResource": teacherResource,
        "textType": textType != null
            ? List<dynamic>.from(textType!.map((x) => x.toJson()))
            : null,
        "textTypeResps": textTypeResps != null
            ? List<dynamic>.from(textTypeResps!.map((x) => x.toJson()))
            : null,
        "topBook": topBook,
        "topics":
            topics != null ? List<dynamic>.from(topics!.map((x) => x)) : null,
        "traditionalTitle": traditionalTitle,
        "uploadDate": uploadDate,
        "viewMode": viewMode,
      };
}
